home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / MATH / NRPAS13 / DDPOLY.DEM < prev    next >
Text File  |  1991-04-29  |  1KB  |  61 lines

  1. PROGRAM d5r2(input,output);
  2. (* driver for routine DDPOLY *)
  3. (* polynomial (x-1)**5 *)
  4. CONST
  5.    nc=6;
  6.    nd=5;   (* nd=nc-1 *)
  7.    np=20;
  8. TYPE
  9.    words = PACKED ARRAY [1..15] OF char;
  10.    glcarray = ARRAY [1..nc] OF real;
  11.    glpdarray = ARRAY [1..nd] OF real;
  12. VAR
  13.    i,j : integer;
  14.    x : real;
  15.    c : glcarray;
  16.    pd : glpdarray;
  17.    d : ARRAY [1..nd,1..np] OF real;
  18.    a : ARRAY [1..nd] OF words;
  19.    glntop : integer;
  20.    gla : ARRAY [1..33] OF real;
  21.  
  22. FUNCTION power(x: real; n: integer): real;
  23. BEGIN
  24.    IF (n=0) THEN power := 1.0 ELSE power := x*power(x,n-1)
  25. END;
  26.  
  27. (*$I MODFILE.PAS *)
  28. (*$I GAMMLN.PAS *)
  29.  
  30. (*$I FACTRL.PAS *)
  31.  
  32. (*$I DDPOLY.PAS *)
  33.  
  34. BEGIN
  35.    glntop := 0;
  36.    gla[1] := 1.0;
  37.    a[1] := 'polynomial:    '; a[2] := 'first deriv:   ';
  38.    a[3] := 'second deriv:  '; a[4] := 'third deriv:   ';
  39.    a[5] := 'fourth deriv:  ';
  40.    c[1] := -1.0; c[2] := 5.0; c[3] := -10.0;
  41.    c[4] := 10.0; c[5] := -5.0; c[6] := 1.0;
  42.    FOR i := 1 to np DO BEGIN
  43.       x := 0.1*i;
  44.       ddpoly(c,nc,x,pd,nc-1);
  45.       FOR j := 1 to nc-1 DO BEGIN
  46.          d[j,i] := pd[j]
  47.       END
  48.    END;
  49.    FOR i := 1 to nc-1 DO BEGIN
  50.       writeln(' ':7,a[i]);
  51.       writeln('x':12,'DDPOLY':17,'actual':15);
  52.       FOR j := 1 to np DO BEGIN
  53.          x := 0.1*j;
  54.          writeln(x:15:6,d[i,j]:15:6,
  55.            (factrl(nc-1)/factrl(nc-i))*power(x-1.0,nc-i):15:6)
  56.       END;
  57.       writeln('press ENTER to continue...');
  58.       readln
  59.    END
  60. END.
  61.